﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Tulde.WindowsPhone.Music;

namespace MP3tunes.LockerPlayer.Pages
{
    public partial class SettingsManager : PhoneApplicationPage
    {
        public SettingsManager()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(SettingsManager_Loaded);
        }

        void SettingsManager_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                this.enablePNS.IsChecked = SettingsProvider.Settings.EnablePNS;
                this.enablePNSNot.IsChecked = SettingsProvider.Settings.SuppressEnablePNSDialog;
                this.saveCreds.IsChecked = SettingsProvider.Settings.SaveLogonCredentials;
            }
            catch { }
        }

        private bool GetChecked(CheckBox box)
        {
            if (box.IsChecked.HasValue)
            {
                return box.IsChecked.Value;
            }
            else
            {
                return false;
            }
        }

        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            SettingsProvider.Settings.EnablePNS = GetChecked(this.enablePNS);
            SettingsProvider.Settings.SuppressEnablePNSDialog = GetChecked(this.enablePNSNot);
            SettingsProvider.Settings.SaveLogonCredentials = GetChecked(this.saveCreds);

          


        }

        private void resetBtn_Click(object sender, RoutedEventArgs e)
        {
            SecurityProvider.ClearCredentials();
        }
    }
}